package com.app.babygo;




import com.app.babygo.dbservice.AchievementAdapter;

import android.os.Bundle;
import android.content.Intent;
import android.view.View;

public class TaskUnlock extends CameraBasePage {
	
	protected static final String TAG = "TaskUnlockView";
	protected static final String TASK_ID_KEY = "TaskID";
	protected String TaskID;
	protected String PicturePath;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Intent intent = this.getIntent();
		TaskID = intent.getStringExtra(TaskDetail.TASK_ID_KEY);
		PicturePath = this.getFilesDir() +  
				  "/achievement_pic_" + ChildChoose.SelectedChildID + 
				  "_" + TaskID + ".jpg";
	}

	@Override
	protected void previewStageOK(View v){
		super.previewStageOK(v);
		//camera.takePicture(PicturePath);
	}
	
	@Override
	protected void previewStageCancel(View v){
		// TODO: clean up picture file
		super.previewStageCancel(v);
	}
	
	@Override
	protected void confirmStageOK(View v){
		unlockAchievement(v);
		TaskDetail.expireCurrentView();
		super.confirmStageOK(v);
	}
	
	protected void unlockAchievement(View v) {
		AchievementAdapter db = new AchievementAdapter(v.getContext());
		db.open();
		db.unlockAchievement(TaskID, ChildChoose.SelectedChildID, PicturePath);
		db.close();
	}
}
